<?php

$v_id_request = mysql_real_escape_string($id_request);
$v_status = mysql_real_escape_string($status);

if ($v_id_request <> "kosong") {
    if (empty($v_status)){
        $query = "select jumlah_beli from  request_transaksi where id_request=" . $v_id_request;
    } else {
        $query = "select jumlah_beli from  request_transaksi where id_request=" . $v_id_request. " and status = ".$v_status;
    }
    $result = mysql_query($query. " order by status desc");
    $row = mysql_fetch_assoc($result);
    $jmlBeli = $row['jumlah_beli'];


    $query = "SELECT count(*) as total  FROM flag_message_outbox WHERE id_request = " . $v_id_request . " and status = 0";
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);
    $proses = $row['total'];

    $query = "SELECT count(*) as total  FROM flag_message_outbox WHERE id_request = " . $v_id_request . " and status = 1";
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);
    $terkirim = $row['total'];

    $query = "SELECT count(*) as total  FROM flag_message_outbox WHERE id_request = " . $v_id_request . " and status = -2";
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);
    $gagal = $row['total'];

    $menunggu = $jmlBeli - $proses - $terkirim - $gagal;

    $sql = "SELECT * FROM flag_message_outbox WHERE id_request = " . $v_id_request;    
    $result = mysql_query($sql);
    echo "<table border=1 class='flat-table flat-table-1' style='width:100%; margin-bottom:0;'>
          <thead>    
                <tr>
                    <th style='text-align:left;'>No. Handphone</th>
                    <th style='text-align:left;'>Status</th>
                </tr>
                <tr>
                    <td style='text-align:center; background-color:black; color:white;' colspan=2>Proses: $proses;   Terkirim: $terkirim;  Gagal: $gagal;</td>
                </tr>
          <thead>
          </table>
          <div style='overflow:hidden; overflow-y: scroll; height: 200px; background-color:#e7eaef;'>
          <table class='flat-table flat-table-1' style='width:100%;'>
          </tbody>";    
    if (mysql_num_rows($result) > 0) {

        while ($row = mysql_fetch_array($result)) {
            if ($row['status'] == '0') {
                $t_status = 'Proses';
            } else if ($row['status'] == '1') {
                $t_status = 'Terkirim';
            } else {
                $t_status = 'Gagal';
            }
            echo "<tr>";
            echo "<td align=left style='padding-left:2%;'>" . $row['receiver'] . "</td>";
            echo "<td align=left style='padding-left:7%;'>" . $t_status . "</td>";
            echo "</tr>";
        }
        echo "<tr>";
        echo "<td align=center colspan=2>Proses: $proses;   Terkirim: $terkirim;  Gagal: $gagal; </td>";
        echo "</tr>";
    } else {
        echo "<tr>";
        echo "<td colspan=2 align=center>No Data...</td>";
        echo "</tr>";
    }
    echo"</div>
          </tbody>
          </table>";
}
?> 

